package com.example.zuoye;

import android.content.ClipData;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;
import java.util.Locale;

/**
 * Created by Administrator on 2022/6/6.
 */

public  class MyAdapter extends BaseAdapter{

    private Context mContext;

    private List<String> texts;
    private List<Integer> images;

    public MyAdapter(Context mContext,List<String> texts,List<Integer> images)
    {
        this.mContext=mContext;
        this.texts=texts;
        this.images=images;
    }

    @Override
    public int getCount() {
        return texts.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null)
        {
            convertView= LayoutInflater.from(mContext).inflate(R.layout.item,null);
            ItemViewCache viewCache=new ItemViewCache();
            viewCache.mTextView=(TextView)convertView.findViewById(R.id.itemListView4Txt);
            viewCache.mImageView=(ImageView)convertView.findViewById(R.id.itemListView4Img);
            convertView.setTag(viewCache);
        }
        ItemViewCache cache=(ItemViewCache) convertView.getTag();
        cache.mTextView.setText(texts.get(position));
        cache.mImageView.setImageResource(images.get(position));
        return convertView;
    }

    private class ItemViewCache
    {
        public TextView mTextView;
        public ImageView mImageView;
    }

}
